﻿namespace MPIS

open System
open System.IO
open Microsoft.SqlServer.Dts.Runtime
open Microsoft.SqlServer.Dts.Tasks.ScriptTask
open System.Xml

module ISPackage_LoadProg = 

    let Load = fun pkgPath pkgSrcTyp svr usr pwd ->
        let ISPkg = new Application()
        match pkgSrcTyp with
        | "file" ->
            match File.Exists(pkgPath) with
            | true ->
                let p = ISPkg.LoadPackage(pkgPath, null)
                let r = p.Execute()
                1
            | _ ->
                -1
        | "sql" ->
            match ISPkg.ExistsOnSqlServer(pkgPath, svr, usr, pwd) with
            | true ->
                ISPkg.LoadFromSqlServer(pkgPath, svr, usr, pwd, null).Execute() |> ignore
                2
            | _ ->
                -1
        | "dts" ->
            match ISPkg.ExistsOnDtsServer(pkgPath, svr) with
            | true ->
                ISPkg.LoadFromDtsServer(pkgPath, svr, null).Execute() |> ignore
                3
            | _ ->
                -1
        | _ ->
            -2
